package com.hyh.prize.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hyh.prize.entity.Dict;
import com.hyh.prize.service.DictSerive;
import com.hyh.prize.vo.Yyt;
import com.lww.springcloudapi.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin/dict/")
@Api(tags = "字典表数据查询")
public class DictController {
    @Resource
    private DictSerive dictSerive;

    @GetMapping("get/jpLeve")
    @ApiOperation("获取所有奖品等级")
    public Result getJpLeve(){
        QueryWrapper queryWrapper=new QueryWrapper();

        queryWrapper.eq("parent","4");
        List list = dictSerive.list(queryWrapper);
        return Result.ok(list);
    }

    @GetMapping("get/GgkType")
    @ApiOperation("获取所有刮刮卡状态")
    public Result getGgkType(){
        QueryWrapper queryWrapper=new QueryWrapper();

        queryWrapper.eq("parent","2");
        List list = dictSerive.list(queryWrapper);
        return Result.ok(list);
    }

    @GetMapping("get/CzType")
    @ApiOperation("获取所有操作类型")
    public Result getCzType(){
        QueryWrapper queryWrapper=new QueryWrapper();

        queryWrapper.eq("parent","1");
        List list = dictSerive.list(queryWrapper);
        return Result.ok(list);
    }

    @GetMapping("get/JpType")
    @ApiOperation("获取所有奖品类型")
    public Result getJpType(){
        QueryWrapper queryWrapper=new QueryWrapper();

        queryWrapper.eq("parent","3");
        List list = dictSerive.list(queryWrapper);
        return Result.ok(list);
    }

    @GetMapping("get/getLeveName")
    @ApiOperation("根据value获取奖品等级名称")
    public String getLeveNameByVul(String value){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("parent","4");
        queryWrapper.eq("value",value);
        Dict dict = dictSerive.getOne(queryWrapper);
        return dict.getCodeName();
    }

    @GetMapping("get/getStateName")
    @ApiOperation("根据value获取刮刮卡状态名称")
    public String getStateName(String value){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("parent","2");
        queryWrapper.eq("value",value);
        Dict dict = dictSerive.getOne(queryWrapper);
        return dict.getCodeName();
    }



    @GetMapping("get/Address")
    @ApiOperation("获取所有地区")
    public Result getAddress(){
        QueryWrapper queryWrapper=new QueryWrapper();

        queryWrapper.eq("parent","26");
        List list = dictSerive.list(queryWrapper);
        return Result.ok(list);
    }


    @GetMapping("get/getAddressName")
    @ApiOperation("根据value获取地区名称")
    public String getAddressName(String value){
        String dName = dictSerive.getDName(value);
        return dName;
    }


    @GetMapping("get/getAddressYyt/{id}")
    @ApiOperation("获取所有地区下的营业厅")
    public Result getAddressYyt(@PathVariable long id){
        List<Yyt> list = dictSerive.getYyt(id);
        return Result.ok(list);
    }

    @GetMapping("get/getYytName/{code}")
    @ApiOperation("获取营业厅信息")
    public Result getYytName(@PathVariable long code){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("parent",code);
        Dict one = dictSerive.getOne(queryWrapper);
        Yyt yyt = dictSerive.getYyt(one);
        return Result.ok(yyt);
    }


}
